#define _CRT_SECURE_NO_WARNINGS 1 
#include<iostream>
using namespace std;

int LastRemaining_Solution(int n, int m) {
    // write code here
    int f = 0;
    for (int i = 2; i <= n; i++)
    { 
        cout << f << endl;
        f = (f + m) % i;
       
    }
        
    return f;

}

int main()
{
    cout <<"final:"<< LastRemaining_Solution(7, 3) << endl;
	return 0;
}